package com.tencreat.mall.controller.app;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.domain.account.vo.MallMyAutoPtVO;
import com.tencreat.domain.mall.vo.KillZoneVO;
import com.tencreat.domain.mall.vo.PtIntegralVO;
import com.tencreat.domain.pt.dto.OpenedSvipDTO;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.domain.mall.dto.OrderMallSubmitDTO;
import com.tencreat.domain.pt.vo.*;
import com.tencreat.domain.pt.dto.LotteryAfterDTO;
import com.tencreat.mapper.pt.MallPtGoodsMapper;
import com.tencreat.service.pt.IMallPtService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

@Api(tags = "4-拼团相关api")
//@RestController
@RequestMapping("/api/mobile/pt")
public class MobilePtController extends BaseController {
    //@Autowired
    MallPtGoodsMapper mallPtGoodsMapper;

    //@Autowired
    IMallPtService mallPtService;

    /**
     * 查询拼团专区列表
     */
    @GetMapping("/killZoneList")
    @ApiOperation("查询拼团专区列表")
    public HttpResult<List<KillZoneVO>> ptZoneList() {
        return HttpResult.ok(mallPtGoodsMapper.ptZoneList());
    }


    /**
     * 签到领取拼团券
     */
    @ApiOperation("签到领取拼团券")
    @PutMapping("/signInPtCoupon/{uuid}")
    public HttpResult<?> signInPtCoupon(@PathVariable String uuid) {
        return mallPtService.signInPtCoupon(uuid);
    }


    /**
     * 拼团商品列表
     */
    @ApiOperation("拼团商品列表")
    @GetMapping("/ptGoodList")
    @ApiIgnore
    public HttpResult<IPage<ResPtGoodsListAppVO>> ptGoodList(@ApiParam("分页页码") @RequestParam Integer pageNum,
                                                             @ApiParam("分页大小") @RequestParam Integer pageSize,
                                                             @ApiParam("专区id") @RequestParam(required = false) Integer zoneId) {
        Page<ResPtGoodsListAppVO> page = new Page<>(pageNum, pageSize);
        return HttpResult.ok(mallPtService.ptGoodList(page, zoneId,getLoginCheck()));
    }

    /**
     * 查询拼团商品详情
     */
    @ApiOperation("查询拼团商品详情")
    @GetMapping("/getDetail")
    public HttpResult<ResPtGoodsDetailAppVO> getDetailApp(@ApiParam("拼团id,列表返回的id") @RequestParam Integer id) {
        return HttpResult.ok(mallPtService.getDetailApp(id, getLoginCheck()));
    }

    /**
     * 查询拼团记录
     */
    @ApiOperation("查询拼团记录")
    @GetMapping("/getPtRecord")
    public HttpResult<IPage<ResPtRecordAppVO>> getPtRecord(@ApiParam("分页页码") @RequestParam Integer pageNum,
                                                           @ApiParam("分页大小") @RequestParam Integer pageSize,
                                                           @ApiParam("专区id") @RequestParam(required = false) Integer zoneId,
                                                           @ApiParam("活动状态") @RequestParam(required = false) Integer activityStatus,
                                                           @ApiParam("拼中状态") @RequestParam(required = false) Integer status
    ) {
        Page<ResPtRecordAppVO> page = new Page<>(pageNum, pageSize);
        return HttpResult.ok(mallPtService.getPtRecord(page, zoneId, activityStatus,status, getLoginCheck()));
    }

    /**
     * 中奖之后兑换或者发货
     */
    @ApiOperation("中奖之后兑换或者发货")
    @PutMapping("/lotteryAfterOperation")
    public HttpResult<?> lotteryAfterOperation(@Validated @RequestBody LotteryAfterDTO vo) {
        return mallPtService.lotteryAfterOperation(vo, getLoginCheck());
    }



    /**
     * 开通试用SVIP
     */
    @ApiOperation("开通试用SVIP")
    @PostMapping("/ptSvipTryOut")
    @ApiIgnore
    public HttpResult<?> ptSvipTryOut() {
        return mallPtService.ptSvipTryOut(getLoginCheck().getAccountLogin().getUuid());
    }

    @ApiOperation("开通SVIP")
    @PostMapping("/balanceOpenedSvip")
    @ApiIgnore
    public HttpResult<?> balanceOpenedSvip(@RequestBody OpenedSvipDTO dto) {
        return mallPtService.balanceOpenedSvip(dto,getLoginCheck());
    }

    /**
     * 查询拼团券使用记录
     */
    @ApiOperation("查询拼团券使用记录")
    @GetMapping("/selectPtCouponRecord")
    public HttpResult<IPage<ResPtCouponRecordAppVO>> selectPtCouponRecord(@ApiParam("分页页码") @RequestParam Integer pageNum,
                                                                          @ApiParam("分页大小") @RequestParam Integer pageSize) {
        Page<ResPtCouponRecordAppVO> page = new Page<>(pageNum, pageSize);
        return HttpResult.ok(mallPtService.selectPtCouponRecord(page, getLoginCheck()));
    }


    /**
     * 兑换现金券
     */
    @ApiOperation("兑换现金券")
    @PostMapping("exchangeCashCoupon")
    @ApiIgnore
    public HttpResult<?> exchangeCashCoupon() {
        return mallPtService.exchangeCashCoupon(getLoginCheck());
    }

    /**
     * 查询我的现金券
     */
    @ApiOperation("查询我的现金券")
    @GetMapping("getHaveCashCoupon")
    public HttpResult<List<HaveCashCouponVO>> getHaveCashCoupon() {
        return HttpResult.ok(mallPtService.getHaveCashCoupon(getLoginCheck()));
    }


    /**
     * 开启自动拼团
     */
    @ApiOperation("开启自动拼团")
    @PostMapping("/startAutoPT")
    @ApiIgnore
    public HttpResult<?> startAutoPT(@Validated @RequestBody OrderMallSubmitDTO param) {
        return mallPtService.startAutoPT(param, getLoginCheck());
    }


    /**
     * 查询奖金池
     */
    @ApiOperation("app查询奖金池")
    @GetMapping("/getBonusPoolInfo")
    @ApiIgnore
    public HttpResult<ResBonusPoolAppVO> getBonusPoolInfo() {
        return HttpResult.ok(mallPtService.getBonusPoolInfo());
    }


    @ApiOperation("查看我的收益记录")
    @GetMapping("/getMyEarnings")
    public HttpResult<IPage<EarningsVO>> getMyEarnings(
            @ApiParam("分页页码") @RequestParam Integer pageNum,
            @ApiParam("分页条数") @RequestParam Integer pageSize) {
        Page<EarningsVO> page = new Page<>(pageNum, pageSize);
        return HttpResult.ok(mallPtService.getMyEarnings(page, getLoginCheck()));
    }

    /**
     * 管理我的自动拼团
     */
    @ApiOperation("管理我的自动拼团")
    @PostMapping("/managementMyAutoPt")
    @ApiIgnore
    public HttpResult<List<MallMyAutoPtVO>> managementMyAutoPt() {
        return mallPtService.managementMyAutoPt(getLoginCheck().getAccountLogin().getUuid());
    }

    /**
     * 修改自动拼团状态
     */
    @ApiOperation("修改自动拼团状态,id传递自动拼团列表返回的id")
    @PostMapping("/updateAutoPtStatus")
    @ApiIgnore
    public HttpResult<?> updateAutoPtStatus(@RequestBody ReqIdParam param) {
        return mallPtService.updateAutoPtStatus(param,getLoginCheck().getAccountLogin().getUuid());
    }

}
